package com.example.helloworld.slice;

import com.example.helloworld.ResourceTable;
import ohos.aafwk.ability.AbilitySlice;
import ohos.aafwk.content.Intent;
import ohos.agp.components.Button;
import ohos.agp.components.Text;
import ohos.agp.components.Component;

public class MainAbilitySlice extends AbilitySlice {
    int clickCount = 0;
    @Override
    public void onStart(Intent intent) {
        super.onStart(intent);
        // 设置页面内容
        super.setUIContent(ResourceTable.Layout_ability_main);


        Button button = (Button) findComponentById(ResourceTable.Id_button);
        Text text = (Text) findComponentById(ResourceTable.Id_text_helloworld);
        text.setText("点击" + clickCount + "次");
        button.setClickedListener(new Component.ClickedListener() {
            @Override
            public void onClick(Component component) {
                clickCount += 1;
                text.setText("点击" + clickCount + "次");
            }
        });
    }
}
